﻿@{
    ViewBag.Title = L("Ribbon_PageGroups");
}

@model PageModule

<div class="lineinput">
    <div id="grid"></div>
</div>
<script type="text/x-kendo-template" id="template">
    <div style="text-align:right;">
        @Html.CultureDropdownList("CultureName", (string)ViewBag.CultureName, new { style="float:left; text-align:left;" })
        <button type="button" onclick="hashgo('@Model.BackendEditUrl?cultureName='+cultureName);" class="k-button k-button-icontext"><span class="k-icon k-add"></span>@LRaw("Ribbon_CreateGroup")</button>
        <button type="button" onclick="ajaxDel($('input[name=GroupID]').checkedVal())" class="k-button k-button-icontext"><span class="k-icon k-delete"></span>@LRaw("Ribbon_DeleteGroup")</button>
    </div>
</script>
<script type="text/javascript">
    var cultureName = '@CultureName';
    $(document).ready(function () {
        $('#grid').grid({
            transport: {
                read: {
                    url: '@Url.Action("QueryPageGroups")',
                    dataType: "json",
                    type: "POST",
                    data: {
                        cultureName: function () {
                            return cultureName;
                        }
                    }
                }
            },
            columns: [
                { title: 'chkall', template: '<input type="checkbox" value="#= GroupID #" name="GroupID"/>', width: "28px" },
                {
                    title: '@LRaw("PageGroup_GroupName")', template: '#= GroupName #\
                <div class="actionpanel">\
                    <a onclick="hashgo(\'@Model.BackendPublicUrl?groupid=#= GroupID #&cultureName=\'+cultureName);" title="@LRaw("PageGroup_Create")" href="javascript:void(0);"><span class="k-icon k-i-restore"></span> @LRaw("PageGroup_Create") </a>\
                    <a onclick="hashgo(\'@Model.BackendEditUrl?groupid=#= GroupID #&cultureName=\'+cultureName);" title="@LRaw("Edit")" href="javascript:void(0);"><span class="k-icon k-edit"></span> @LRaw("Edit") </a> \
                    <a onclick="ajaxDel(#= GroupID #);" title="@LRaw("Delete")" href="javascript:void(0);"><span class="k-icon k-delete"></span> @LRaw("Delete") </a>\
                    <a class="moz-move-up" onclick="ajaxSort(#= GroupID #, false);" title="@LRaw("MoveUp")" href="javascript:void(0);"><span class="k-icon k-i-arrow-n"></span> @LRaw("MoveUp") </a>\
                    <a class="moz-move-down" onclick="ajaxSort(#= GroupID #, true);" title="@LRaw("MoveDown")" href="javascript:void(0);"><span class="k-icon k-i-arrow-s"></span> @LRaw("MoveDown") </a>\
                </div>' },
                { template: '#= RoleLevel #', title: '@LRaw("RoleLevel")' },
                { template: '#= Key #', title: '@LRaw("Key")' },
                { template: '#= CreateDate #', title: '@LRaw("CreateDate")' }
            ],
            toolbar: '#template',
            checkall: 'GroupID',
            gridin: {
                dataBound: function () {
                    $('a.moz-move-up:first').remove();
                    $('a.moz-move-down:last').remove();
                },
                sortable: false
            }
        }).find('#CultureName').kendoDropDownList({
            change: function () {
                cultureName = this.value();
                grid.refresh();
            }
        });
    });

    function ajaxDel(ids){
        if(!ids) {
            alert('@LRaw("Action_SelectedFirst", L("Action_PageGroup"))');
            return;
        }
        ajaxDelete('@Url.Action("DeletePageGroups")',
        {
            ids:function(){
                return ids;
            },
            cultureName: function () {
                return cultureName;
            }
        }, 
        function(data){
            grid.refresh();
        }, 
        '@LRaw("Action_DeletedPageGroupConfirm")');
    }

    function ajaxSort(id, isDown) {
        ajaxUdSort('@Url.Action("SortPageGroup")', {
            cultureName: function () { return cultureName; }
        }, id, isDown, function (data) {
            grid.refresh();
        });
    }
</script>